package cn.yav.entity.base;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * All rights Reserved, Designed By www.yavyun.net
 *
 * @version V1.0
 * @Title: yavpingtai
 * @Package cn.yav.entity.base
 * @Description: ${todo}
 * @author: zn
 * @date: 2019/12/14 16:24
 * @Copyright: 2019 www.yavyun.net Inc. All rights reserved.
 * 注意：本内容仅限于浙江智飨科技内部传阅，禁止外泄以及用于其他的商业目
 */
public class WeightUtils {
    public static Map<String,Object> getIsNormal(String[] standards,Double weights,Double foodWeight){
        Map<String,Object> returnMap = new HashMap<String,Object>();
        if(!IsEmptyUtils.isEmpty(standards[0])){
            if(!IsEmptyUtils.isEmpty(standards[1])){
                //上下都浮动
                //核定完成重量
                Double weightUp = weights*(1+Double.valueOf(standards[0]));
                Double weightDown = weights*(1-Double.valueOf(standards[1]));
                //故标准格式为 0.05,0.04  即大于x*(1+0.05)为异常  小于x*(1-0.04)为异常  x*(1-0.05)<x<x*(1+0.05) 为正常
                //数据库标准改成 , ,之前是往上浮动百分之几 x*(1+百分之几(标准))，,之后是往下浮动百分之几 x*(1-百分之几(标准))
                if(weightDown<foodWeight&&foodWeight<weightUp){
                    returnMap.put("isNormal", 1);
                }else{
                    returnMap.put("isNormal", 2);
                }
                //放入核定完成重量，避免查询的时候for循环遍历判断
                returnMap.put("shuldeBeWeight", weightDown+"-"+weightUp);
            }else{
                //上浮动，下不浮动
                //核定完成重量
                Double weightUp = weights*(1+Double.valueOf(standards[0]));
                //故标准格式为 0.05,0.04  即大于x*(1+0.05)为异常  小于x*(1-0.04)为异常  x*(1-0.05)<x<x*(1+0.05) 为正常
                //数据库标准改成 , ,之前是往上浮动百分之几 x*(1+百分之几(标准))，,之后是往下浮动百分之几 x*(1-百分之几(标准))
                if(foodWeight<weightUp){
                    returnMap.put("isNormal", 1);
                }else{
                    returnMap.put("isNormal", 2);
                }
                //放入核定完成重量，避免查询的时候for循环遍历判断
                returnMap.put("shuldeBeWeight", "-"+weightUp);
            }
        }else{
            if(!IsEmptyUtils.isEmpty(standards[1])){
                //下浮动，上不浮动
                //核定完成重量
                Double weightDown = weights*(1-Double.valueOf(standards[1]));
                //故标准格式为 0.05,0.04  即大于x*(1+0.05)为异常  小于x*(1-0.04)为异常  x*(1-0.05)<x<x*(1+0.05) 为正常
                //数据库标准改成 , ,之前是往上浮动百分之几 x*(1+百分之几(标准))，,之后是往下浮动百分之几 x*(1-百分之几(标准))
                if(weightDown<foodWeight){
                    returnMap.put("isNormal", 1);
                }else{
                    returnMap.put("isNormal", 2);
                }
                //放入核定完成重量，避免查询的时候for循环遍历判断
                returnMap.put("shuldeBeWeight", weightDown+"-");
            }else{
                //上下都不浮动
                //核定完成重量
                //故标准格式为 0.05,0.04  即大于x*(1+0.05)为异常  小于x*(1-0.04)为异常  x*(1-0.05)<x<x*(1+0.05) 为正常
                //数据库标准改成 , ,之前是往上浮动百分之几 x*(1+百分之几(标准))，,之后是往下浮动百分之几 x*(1-百分之几(标准))
                if(weights==foodWeight){
                    returnMap.put("isNormal", 1);
                }else{
                    returnMap.put("isNormal", 2);
                }
                //放入核定完成重量，避免查询的时候for循环遍历判断
                returnMap.put("shuldeBeWeight", weights.toString());
            }
        }
        return returnMap;
    }
    public Map<String,String> getTransEntity(Map<String,String> map,Double weights,List<Map<String,Object>> dateLong){
        int i = 5;
        switch(i){
            case 0:
                //System.out.println("morning weight");
                Double reqWeight = Double.valueOf(map.get("foodWeight"));
                //这一步获取标准
                String[] standards = map.get("standard").split(",");
                Map<String,Object> norShouldMap = WeightUtils.getIsNormal(standards, weights, reqWeight);
                String isNomal = String.valueOf(norShouldMap.get("isNormal"));
                String shuldeBeWeight = String.valueOf(norShouldMap.get("shuldeBeWeight"));
                map.put("isNormal", isNomal);
                map.put("shuldeBeWeight", shuldeBeWeight);
                break;
            case 1:
                //System.out.println("noon weight");
                break;
            case 2:
                //System.out.println("evening weight");
                break;
            default:
                //System.out.println("default");
                break;
        }
        return null;
    }
}
